package com.example.rabbit.three;

import com.example.rabbit.util.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * 队列模式
 * 1.不自动应答
 * 2.不公平分发
 **/
public class Task02 {

    public static final String ACK_QUEUE = "ack_queue";


    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtils.getChannel();
        channel.queueDeclare(ACK_QUEUE, false, false, false, null);

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            String message = scanner.next();
            // 持久化 essageProperties.PERSISTENT_TEXT_PLAIN
            channel.basicPublish("", ACK_QUEUE,null, message.getBytes("UTF-8"));
            System.out.println("发送消息: " + message);
        }

    }
}
